﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.ObjectModel;


namespace PreferredZhiTu.Views
{
    public partial class City : PhoneApplicationPage
    {        
        public City()
        {
            InitializeComponent();            
        }

        public string city;
        private void CityOkButton_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text != "")
            {
                city = textBox1.Text;
                SetCity(city);
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }
        public void SetCity(string City)
        {
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream fs = file.OpenFile("city.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(City);
                sw.Close();
                fs.Close();
            }
        }

       
        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //获取选择的城市名赋值给city
            ListBox lb = (ListBox)listBox1;  // ListBox lb = sender as ListBox;
            ListBoxItem item = (ListBoxItem)this.listBox1.SelectedItem;
           // ListBoxItem item = lb.SelectedItem as ListBoxItem;
            if (null !=item )
            {
                city= item.Content.ToString();                
            }
            SetCity(city);
           NavigationService.Navigate(new Uri("/MainPage.xaml?selectItem=" + listBox1.SelectedIndex, UriKind.Relative));
           
        }
    }
}